<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="名称" prop="number">
        <el-input
          v-model="queryParams.number"
          placeholder="请输入名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="全名" prop="fullName">
        <el-input
          v-model="queryParams.fullName"
          placeholder="请输入全名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职员类别" prop="staffType">
        <el-input
          v-model="queryParams.staffType"
          placeholder="请输入职员类别"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门名称" prop="deptName">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入部门名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-input
          v-model="queryParams.sex"
          placeholder="请输入性别"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出生日期" prop="dateBirth">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.dateBirth"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择出生日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="文化程度" prop="degreeEducation">
        <el-input
          v-model="queryParams.degreeEducation"
          placeholder="请输入文化程度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话" prop="telephone">
        <el-input
          v-model="queryParams.telephone"
          placeholder="请输入电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="移动电话" prop="mobilePhone">
        <el-input
          v-model="queryParams.mobilePhone"
          placeholder="请输入移动电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="idNumber">
        <el-input
          v-model="queryParams.idNumber"
          placeholder="请输入身份证号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职务" prop="post">
        <el-input
          v-model="queryParams.post"
          placeholder="请输入职务"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入职日期" prop="entryDate">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.entryDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择入职日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="离职日期" prop="departureDate">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.departureDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择离职日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="户名" prop="accountName">
        <el-input
          v-model="queryParams.accountName"
          placeholder="请输入户名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开户银行" prop="bankDeposit">
        <el-input
          v-model="queryParams.bankDeposit"
          placeholder="请输入开户银行"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="银行账号" prop="bankAccount">
        <el-input
          v-model="queryParams.bankAccount"
          placeholder="请输入银行账号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省份" prop="province">
        <el-input
          v-model="queryParams.province"
          placeholder="请输入省份"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="城市" prop="city">
        <el-input
          v-model="queryParams.city"
          placeholder="请输入城市"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="住址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入住址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电子邮件" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入电子邮件"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="remarks">
        <el-input
          v-model="queryParams.remarks"
          placeholder="请输入备注"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否进行信用管理" prop="creditManagement">
        <el-input
          v-model="queryParams.creditManagement"
          placeholder="请输入是否进行信用管理"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班组" prop="team">
        <el-input
          v-model="queryParams.team"
          placeholder="请输入班组"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工种" prop="profession">
        <el-input
          v-model="queryParams.profession"
          placeholder="请输入工种"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务组" prop="businessGroup">
        <el-input
          v-model="queryParams.businessGroup"
          placeholder="请输入业务组"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['base:person:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['base:person:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['base:person:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['base:person:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="personList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="人员id" align="center" prop="personId" />
      <el-table-column label="名称" align="center" prop="number" />
      <el-table-column label="全名" align="center" prop="fullName" />
      <el-table-column label="职员类别" align="center" prop="staffType" />
      <el-table-column label="部门名称" align="center" prop="deptName" />
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="出生日期" align="center" prop="dateBirth" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dateBirth, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="文化程度" align="center" prop="degreeEducation" />
      <el-table-column label="电话" align="center" prop="telephone" />
      <el-table-column label="移动电话" align="center" prop="mobilePhone" />
      <el-table-column label="身份证号" align="center" prop="idNumber" />
      <el-table-column label="职务" align="center" prop="post" />
      <el-table-column label="入职日期" align="center" prop="entryDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.entryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="离职日期" align="center" prop="departureDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.departureDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="户名" align="center" prop="accountName" />
      <el-table-column label="开户银行" align="center" prop="bankDeposit" />
      <el-table-column label="银行账号" align="center" prop="bankAccount" />
      <el-table-column label="省份" align="center" prop="province" />
      <el-table-column label="城市" align="center" prop="city" />
      <el-table-column label="住址" align="center" prop="address" />
      <el-table-column label="电子邮件" align="center" prop="email" />
      <el-table-column label="备注" align="center" prop="remarks" />
      <el-table-column label="是否进行信用管理" align="center" prop="creditManagement" />
      <el-table-column label="班组" align="center" prop="team" />
      <el-table-column label="工种" align="center" prop="profession" />
      <el-table-column label="业务组" align="center" prop="businessGroup" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['base:person:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['base:person:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改人员对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="名称" prop="number">
          <el-input v-model="form.number" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="全名" prop="fullName">
          <el-input v-model="form.fullName" placeholder="请输入全名" />
        </el-form-item>
        <el-form-item label="职员类别" prop="staffType">
          <el-input v-model="form.staffType" placeholder="请输入职员类别" />
        </el-form-item>
        <el-form-item label="部门名称" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入部门名称" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-input v-model="form.sex" placeholder="请输入性别" />
        </el-form-item>
        <el-form-item label="出生日期" prop="dateBirth">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.dateBirth"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择出生日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="文化程度" prop="degreeEducation">
          <el-input v-model="form.degreeEducation" placeholder="请输入文化程度" />
        </el-form-item>
        <el-form-item label="电话" prop="telephone">
          <el-input v-model="form.telephone" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="移动电话" prop="mobilePhone">
          <el-input v-model="form.mobilePhone" placeholder="请输入移动电话" />
        </el-form-item>
        <el-form-item label="身份证号" prop="idNumber">
          <el-input v-model="form.idNumber" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="职务" prop="post">
          <el-input v-model="form.post" placeholder="请输入职务" />
        </el-form-item>
        <el-form-item label="入职日期" prop="entryDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.entryDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择入职日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="离职日期" prop="departureDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.departureDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择离职日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="户名" prop="accountName">
          <el-input v-model="form.accountName" placeholder="请输入户名" />
        </el-form-item>
        <el-form-item label="开户银行" prop="bankDeposit">
          <el-input v-model="form.bankDeposit" placeholder="请输入开户银行" />
        </el-form-item>
        <el-form-item label="银行账号" prop="bankAccount">
          <el-input v-model="form.bankAccount" placeholder="请输入银行账号" />
        </el-form-item>
        <el-form-item label="省份" prop="province">
          <el-input v-model="form.province" placeholder="请输入省份" />
        </el-form-item>
        <el-form-item label="城市" prop="city">
          <el-input v-model="form.city" placeholder="请输入城市" />
        </el-form-item>
        <el-form-item label="住址" prop="address">
          <el-input v-model="form.address" placeholder="请输入住址" />
        </el-form-item>
        <el-form-item label="电子邮件" prop="email">
          <el-input v-model="form.email" placeholder="请输入电子邮件" />
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="是否进行信用管理" prop="creditManagement">
          <el-input v-model="form.creditManagement" placeholder="请输入是否进行信用管理" />
        </el-form-item>
        <el-form-item label="班组" prop="team">
          <el-input v-model="form.team" placeholder="请输入班组" />
        </el-form-item>
        <el-form-item label="工种" prop="profession">
          <el-input v-model="form.profession" placeholder="请输入工种" />
        </el-form-item>
        <el-form-item label="业务组" prop="businessGroup">
          <el-input v-model="form.businessGroup" placeholder="请输入业务组" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPerson, getPerson, delPerson, addPerson, updatePerson, exportPerson } from "@/api/base/person";

export default {
  name: "Person",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 人员表格数据
      personList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        number: undefined,
        fullName: undefined,
        staffType: undefined,
        deptName: undefined,
        sex: undefined,
        dateBirth: undefined,
        degreeEducation: undefined,
        telephone: undefined,
        mobilePhone: undefined,
        idNumber: undefined,
        post: undefined,
        entryDate: undefined,
        departureDate: undefined,
        accountName: undefined,
        bankDeposit: undefined,
        bankAccount: undefined,
        province: undefined,
        city: undefined,
        address: undefined,
        email: undefined,
        remarks: undefined,
        creditManagement: undefined,
        team: undefined,
        profession: undefined,
        businessGroup: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询人员列表 */
    getList() {
      this.loading = true;
      listPerson(this.queryParams).then(response => {
        this.personList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        personId: undefined,
        number: undefined,
        fullName: undefined,
        staffType: undefined,
        deptName: undefined,
        sex: undefined,
        dateBirth: undefined,
        degreeEducation: undefined,
        telephone: undefined,
        mobilePhone: undefined,
        idNumber: undefined,
        post: undefined,
        entryDate: undefined,
        departureDate: undefined,
        accountName: undefined,
        bankDeposit: undefined,
        bankAccount: undefined,
        province: undefined,
        city: undefined,
        address: undefined,
        email: undefined,
        remarks: undefined,
        creditManagement: undefined,
        team: undefined,
        profession: undefined,
        businessGroup: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.personId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加人员";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const personId = row.personId || this.ids
      getPerson(personId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改人员";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.personId != null) {
            updatePerson(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPerson(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const personIds = row.personId || this.ids;
      this.$confirm('是否确认删除人员编号为"' + personIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delPerson(personIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有人员数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportPerson(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
